package com.pucheng.bracelet.viewmodel.me

import com.clj.fastble.exception.BleException
import com.pucheng.bracelet.app.ble.BleCmd
import com.pucheng.bracelet.app.ble.BleWriteAndNotifyCallback
import com.pucheng.bracelet.app.ble.ClientManager
import com.pucheng.bracelet.app.util.BirthdayToAgeUtil
import com.pucheng.bracelet.app.util.ByteUtils
import com.pucheng.bracelet.app.util.CacheUtil
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel

class MeViewModel :BaseViewModel() {
    fun saveUserInfo() {
        val userInfo = CacheUtil.getUserInfo()
        val sb = StringBuffer(BleCmd.SYNC_USER_INFO)
        sb.append(ByteUtils.intToHex16(userInfo.height))
        sb.append(ByteUtils.intToHex16(userInfo.weight))
        sb.append(ByteUtils.intToHex16(BirthdayToAgeUtil.BirthdayToAge(userInfo.birthday).toInt()))
        sb.append(ByteUtils.intToHex16(userInfo.sex))
        ClientManager.getInstance().sendControlCmd(sb.toString(),object :BleWriteAndNotifyCallback(){
            override fun onCharacteristicChanged(data: ByteArray?) {

            }

            override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
            }

            override fun onWriteFailure(exception: BleException?) {
            }
        })
    }
}